<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 500px;
            margin: 100px auto;
            text-align: center;
            border-collapse: collapse;
        }
        
        th,
        td {
            border: 1px solid #333;
        }
        
        thead tr {
            height: 40px;
            background: #ccc;
        }
    </style>
</head>

<body>
    <table>
        <thead>
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
    <script>
        // 模拟数据
        const datas = [{
            name: '魏璎珞',
            subject: 'JavaScript',
            score: 100,
        }, {
            name: '弘历',
            subject: 'JavaScript',
            score: 98,
        }, {
            name: '傅恒',
            subject: 'Java',
            score: 100,
        }, {
            name: '明玉',
            subject: 'Java',
            score: 95,
        }, ]
        const tbody = document.querySelector('tbody')
        for (let i = 0; i < datas.length; i++) {
            const tr = document.createElement('tr')
            tbody.appendChild(tr)
            const person = datas[i];
            for (const k in person) {
                if (Object.hasOwnProperty.call(person, k)) {
                    const value = person[k];
                    const td = document.createElement('td')
                    tr.appendChild(td)
                    td.innerHTML = value
                }
            }
            const td = document.createElement('td')
            tr.appendChild(td)
            td.innerHTML = '<a href="javascript:;">删除</a>'
            const aList = document.querySelectorAll('a')
            for (let i = 0; i < aList.length; i++) {
                const a = aList[i];
                a.onclick = function() {
                    const tr = this.parentNode.parentNode
                    tr.parentNode.removeChild(tr)
                }
            }
        }
    </script>
</body>

</html>